package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityTaozhuang;
import nero.yncc.com.createart.bean.BeanToazhuang;
import nero.yncc.com.createart.custom.IconView;
import nero.yncc.com.createart.custom.MyRecyclerView;

/**
 * Created by nero on 17-7-6.
 */

public class AdapterTaozhuang extends RecyclerView.Adapter<AdapterTaozhuang.Holder> {
    Context context;
    ArrayList<BeanToazhuang> arrayList;
    ActivityTaozhuang activityTaozhuang;

    public AdapterTaozhuang(Context context, ArrayList<BeanToazhuang> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
        activityTaozhuang = (ActivityTaozhuang) context;
    }


    @Override
    public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_taozhuang, null);
        return  new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, int i) {
        final BeanToazhuang beanToazhuang = arrayList.get(i);
        holder.tv_title.setText(beanToazhuang.getName());
        if (beanToazhuang.isChoose()) {
            holder.icon_choose.setTextColor(context.getResources().getColor(R.color.project_yellow));
        } else {
            holder.icon_choose.setTextColor(context.getResources().getColor(R.color.textColorGray));
        }

        AdapterTaozhuangin adapterTaozhuangin = new AdapterTaozhuangin(context, beanToazhuang.getGoods());
        holder.lv_list.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
        holder.lv_list.setAdapter(adapterTaozhuangin);
//        SomeUtil.setListViewHeightBasedOnChildren(holder.lv_list);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class Holder extends RecyclerView.ViewHolder{
        final IconView icon_choose;
        final TextView tv_title;
        final MyRecyclerView lv_list;

        public Holder(View root) {
            super(root);
            icon_choose = root.findViewById(R.id.icon_choose);
            tv_title = root.findViewById(R.id.tv_title);
            lv_list = root.findViewById(R.id.lv_list);
        }
    }
}
